// pages/Checklist/Checklist.js
import { request } from "../../request/request.js"
Page({

  /**
   * 页面的初始数据
   */
  data: {
    checkType:'',
    checkCategory:'',
    companyCode:'',
    companyName:'',
    checkDate:'',
    checkContent:'',
    unnormalizedValue2:'',
    checkItemName3: '',
    checkItemCode: '',
    checkListItemCode:'',
    checkListItemName:'',
    content:''
  },
  showRule: function () {
    this.setData({
      isRuleTrue: true
    })
  },
  selThis(e) {
    this.setData({
      checkListItemName: e.detail.checkListName,
      checkItemCode: e.detail.checkListCode,
      isRuleTrue: true,
      modalName: e.currentTarget.dataset.target
    })
    console.log(e.detail.checkListName)
  },
  hideModal(e) {
    this.setData({
      modalName: null
    })
  },
  //检查情况跳转
  submitClick1: function () {
    var that=this;
    that.data.content='通过';
    wx.request({
      url: 'http://39.98.173.131:7000/wlhse/api/v3/safety_problem_add',
      method: "POST",
      data: {
        checkType:that.data.checkType,
        checkCategory:that.data.checkCategory,
        checkDate:that.data.checkDate,
        checkContent:that.data.checkContent,
        content:that.data.content,
        companyCode: that.data.companyCode,
        companyName: that.data.companyName,
        checkListItemName: that.data.checkItemName3,
        checkListItemCode: that.data.checkItemCode,
        checkDate: that.data.checkDate,
        checkStaffID: that.data.checkPersonID
      },
      header: {
        'content-type': 'application/json' ,// 默认值
        'Authorization': wx.getStorageSync("token")//读取cookie
      },
      success: function (res) {
        console.log(res.data)
      },
    }),
    wx.showToast({
      title: '提交成功',
      icon: 'success',
      duration: 2000
    })
    this.setData({
      modalName: null
    })
  },
  toHiddenTroouble: function () {
    this.data.content='不通过'
    wx.navigateTo({
      // url: '../problemInput/problemInput?checkType='+this.data.checkType+'&checkCategory='+this.data.checkCategory+'&companyCode='+this.data.companyCode+'&companyName='+this.data.companyName+'&checkDate='+this.data.checkDate+'&checkContent='+ this.data.checkContent+'&checkItemName3='+this.data.checkListItemName+'&checkItemCode='+this.data.checkItemCode+'&content='+this.data.content,
      url:'../hiddenTrouble/hiddenTrouble'
    })
    this.setData({
      modalName: null
    })
  },
  toIllegalInput: function () {
    this.data.content='不通过'
    wx.navigateTo({
    //   url: '../problemInput/problemInput?checkType='+this.data.checkType+'&checkCategory='+this.data.checkCategory+'&companyCode='+this.data.companyCode+'&companyName='+this.data.companyName+'&checkDate='+this.data.checkDate+'&checkContent='+ this.data.checkContent+'&checkItemName3='+this.data.checkListItemName+'&checkItemCode='+this.data.checkItemCode+'&content='+this.data.content,

    url:'../illegalInput/illegalInput'
    })
    this.setData({
      modalName: null
    })
  },
  
  onLoad: function (options) {
    var check_list = []
    var that = this;
    //获取前一页数据
    var checkType=options.CheckType;
    var checkCategory=options.checkCategory;
    var companyCode=options.companyCode;
    var companyName=options.companyName;
    var checkDate=options.checkDate;
    var checkContent=options.checkContent
    that.setData({
      checkType:checkType,
      checkCategory:checkCategory,
      companyCode:companyCode,
      companyName:companyName,
      checkDate:checkDate,
      checkContent:checkContent
    })
    console.log("检查类别="+ this.data.checkType)
    console.log("检查类型="+ this.data.checkCategory)
    console.log("受检单位编码="+ this.data.companyCode)
    console.log("受检单位名称="+ this.data.companyName)
    console.log("检查时间="+ this.data.checkDate)
    console.log("检查内容="+ this.data.checkContent)
    this.getCheckList()
  },
  async getCheckList(){
    let  token=wx.getStorageSync('token')
    console.log(token)
    const header = {Authorization:token};
    const res= await request({url:'/check_list_tree',data:{},header:header});
    console.log(res);
    this.setData({
      unnormalizedValue2: res.data.data
    })
  }
})